package me.nibo.horizontal.listview;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import it.sephiroth.android.library.widget.HListView;
import me.nibo.horizontal.listview.model.Cert;

/**
 * @author nibo
 */
public class SecondActivity extends ActionBarActivity {

    HorizontalListView hListView;
    HListViewSecondAdapter hListViewSecondAdapter;
    List<Cert> certList;
    private GridView gridView;
    private HorizontalScrollListView horizontalScrollListView;
    private HListView myHListView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        initData();
//        initUI();
//        initUI2();
//        initUI3();
        initUI4();
    }



    public void initUI() {
        hListView = (HorizontalListView) findViewById(R.id.my_list_view);
        hListViewSecondAdapter = new HListViewSecondAdapter(this, certList);
        hListView.setAdapter(hListViewSecondAdapter);
        hListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                Toast.makeText(SecondActivity.this, certList.get(position).getName(),
                               Toast.LENGTH_SHORT).show();
            }
        });
        hListView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
    }

    public void initUI2() {
        gridView = (GridView) findViewById(R.id.grid_view);
        hListViewSecondAdapter = new HListViewSecondAdapter(this, certList);
        gridView.setAdapter(hListViewSecondAdapter);

    }

    public void initUI3() {
        horizontalScrollListView = (HorizontalScrollListView) findViewById(R.id.my_list_view2);
        hListViewSecondAdapter = new HListViewSecondAdapter(this, certList);
        horizontalScrollListView.setAdapter(hListViewSecondAdapter);
    }

    public void initUI4() {
        myHListView = (HListView) findViewById(R.id.h_list_view);
        hListViewSecondAdapter = new HListViewSecondAdapter(this, certList);
        myHListView.setAdapter(hListViewSecondAdapter);
        myHListView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
    }

    private void initData() {
        certList = new ArrayList<>();
        Cert cert;
        for (int i = 0; i < 10; i++) {
            cert = new Cert();
            cert.setName("信息通信网络技术工程师" + i);
            cert.setCountTime("共600小时");
            cert.setLearnTime("10小时50分10秒");
            cert.setPro("90%");
            certList.add(cert);
        }
    }
}
